﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using System.Data.Entity.ModelConfiguration;
using System.Data.Entity.ModelConfiguration.Configuration;
using System.ComponentModel.DataAnnotations.Schema;

namespace CarErp.Data.Mappings
{
	public static class MappingEntensions
	{
		public static PrimitivePropertyConfiguration Id<TEntity, TKey>(this EntityTypeConfiguration<TEntity> @this, Expression<Func<TEntity, TKey>> keyExpression)
			where TEntity:class 
			where TKey:struct
		{
			@this.HasKey(keyExpression);

			return @this.Property(keyExpression)
				.HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
		}

		public static void Text<TEntity>(this EntityTypeConfiguration<TEntity> @this, Expression<Func<TEntity, string>> propertyExpression, int length, string columnName = null)
			where TEntity : class
		{
			@this.Property(propertyExpression)
				.HasColumnName(columnName)
				.HasMaxLength(length)
				.IsUnicode()
				.IsRequired();
		}
	}
}
